<script setup lang="ts">
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router';

const router = useRouter()
const form = reactive({
    name: '',
    p: '',
    rp: '',
    date2: '',
    delivery: false,
    type: [],
    resource: '',
    desc: '',
})
const showReg = ref(false)


const onSubmit = () => {
    
    console.log(showReg.value);
    // debugger
    if (showReg.value) {
        if (form.name == '' || form.p == '' || form.rp == '') {
            console.log('请填写信息1');
            return
        } else {
            setTimeout(() => {
                showReg.value = false
                form.p = '';
                form.rp = '';
                console.log('注册完成');
            }, 2000);
        }
    }
    if (form.name == '' || form.p == '') {
        console.log('请填写信息2');
        return
    } else {


        setTimeout(() => {

            form.name = '';
            form.p = '';
            electron.ipcRenderer.send('openChat',showReg.value )
            router.replace('/home')
        }, 2000);
    }


}
const onRegter = () => {
    showReg.value = !showReg.value
    console.log(electron,window.electron);
    
    electron.ipcRenderer.send('reg',showReg.value )
}


function xiexinxi() {
    console.log('kkkkkk');
    
    // api.saveFile(form.desc)

}
async function read() {

//    let aaa  = await api.getFile()
//    console.log(aaa);
//    form.desc = aaa

}
</script>

<template>
    <div class="tile_box dreg" style="padding:10px 20px;color: #000;overflow: hidden;">
         微信  
    </div>
    <!-- <el-input size="small" v-model="form.desc" />  <button @click="xiexinxi">写</button><button @click="read">读</button> -->
    <div style="display: flex; justify-content: center; padding: 20px;color: #000;">
        <el-form :model="form" label-width="auto" style="max-width: 600px">
            <el-form-item label="用户名" label-position="left">
                <el-input size="small" v-model="form.name" />
            </el-form-item>
            <el-form-item label="密      码" label-position="left">
                <el-input size="small" v-model="form.p" />
            </el-form-item>
            <el-form-item label="confirm password" v-if="showReg">
                <el-input size="small" v-model="form.rp" />
            </el-form-item>
            <el-form-item>
                <el-button type="success" style="width: 100%;" @click="onSubmit">{{ showReg ? '注册' : '登录' }}</el-button>
            </el-form-item>
            <el-form-item>
                <span @click="onRegter">{{ showReg ? '已账号去登录' : '没有账号去注册？' }}</span>
            </el-form-item>
        </el-form>

    </div>


</template>
<style src="./index.scss" scoped></style>
